<?php session_start();
    include_once "config/config.php";
    if (isset($_REQUEST['_SESSION']))
    die("Get lost Muppet!");


    $k = $_SESSION['saldainis'];
    $pavad = 'planas';
    date_default_timezone_set('Europe/Vilnius');
    $data = date('Y-m-d H:i:s');
        $timestamp = strtotime('+2 weeks');
        $data2 = date('Y-m-d H:i:s', $timestamp);    
    
    $suma = array();
    $sutartys = array();
    $vart_id = $_SESSION['pajegos'];
    
    $result = mysql_query("SELECT data FROM saskaitos WHERE VartotojaiId = '$vart_id'");
    $row = mysql_fetch_array($result);
        $date_format = is_string($row) ? strtotime($row) : (is_int($row) ? $row : time());
        $y = date('m', $date_format);

    for($i = 0; $i < $k; $i++) {
        $id =(string)$i;
        $pavad = 'planas'.$id;

        $suma[$i] = mysql_real_escape_string($_POST[$id]);
        var_dump($suma[$i]);
        $sutartys[$i] = $_SESSION[$pavad];
        if($suma[$i] != '') {
            mysql_query("INSERT INTO saskaitos (VartotojaiId, Data, Suma, SutartiesId, Issiuntimodata)
                VALUES ('$vart_id',  '$data', '$suma[$i]', '$sutartys[$i]', '$data2')");
        }
            if($data <= date('Y-m-d H:i:s')) {
            header('Location: userpage.php?error=5');
        }


    }
    header('Location: userpage.php?saskaitos');
    
?>